<template>
  <div>
    <div v-if="$data.data.version === '1'">
      <el-link :underline="false"
               v-on:click="edit($data.data)"
               :style='hasPermission'>{{ $data.data.name}}</el-link>
    </div>
    <div v-else>
      <!-- :class="{ 'new-falg': isShowNewTag($data.data.newFlag) }" -->
      <el-link :underline="false"
               v-on:click="routeTo($data.data)"
               :style='hasPermission'>{{ $data.data.name}}</el-link>
    </div>
  </div>
</template>

<script>
import moment from 'moment'
import router from '@/components/storybook/router'
import store from '@/store'
import { LinkComponent } from './LinkComponent'
export default {
  data () {
    return {}
  },
  created () {
  },
  computed: {
    hasPermission () {
      // var _self = this
      // if (_self.$hasPermission('sys:bots:edit')) {
      return 'pointer-events:auto;'
      // } else {
      //   return 'pointer-events:none;'
      // }
    }
  },
  methods: {
    isShowNewTag (dueDate) {
      if (dueDate) {
        return moment().isBefore(dueDate)
      } else {
        return false
      }
    },
    routeTo (data) {
      store.commit('RECORDBOTID', data.id)
      // router.push({ name: 'mspbots-bots-bak-bot-view-index', query: { botId: data.id } })
      // router.push({ name: 'mspbots-bots-bak-bot-design-index', query: { botId: data.id } })
      // localStorage.setItem('botnamefordetailpage', data.name)
      router.push({ path: `bot-${data.id}`, query: { pageid: 'botdetail', botId: data.id, name: data.name } })
      // setTimeout(() => {
      //   let detailIndex = store.state.contentTabs.findIndex(e => e.path === '/BotDetail')
      //   if (detailIndex > -1) {
      //     store.state.contentTabs[detailIndex].query['pageid'] = 'botdetail'
      //     store.state.contentTabs[detailIndex].query['botId'] = data.id
      //   }
      // }, 500)
    },
    edit (data) {
      LinkComponent.$emit('showEdit', data)
    }
    // IsInternal (data) {
    //   let path = window.location.pathname
    //   if (path === '/Bots') {
    //     LinkComponent.$emit('showEdit', data)
    //     return true
    //   } else if (path === '/InternalBots') {
    //     LinkComponent.$emit('showInEdit', data)
    //     return false
    //   } else if (path === '/TemplateBots') {
    //     LinkComponent.$emit('showTyEdit', data)
    //     return false
    //   }
    // }
  }
}
</script>

<style lang="scss" scoped>
.new-falg:after {
  content: "New";
  background-color: red;
  color: #ffffff;
  padding: 2px 4px;
  border-radius: 12px 12px 12px 0;
  font-size: 10px;
}
</style>
